package com.example.myapplication.Media;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import com.example.myapplication.DataBase.DataStoreActivity;
import com.example.myapplication.R;
import com.example.myapplication.Style.StyleActivity;

public class MediaActivity extends AppCompatActivity {
  @Override protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.media_layout);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("多媒体实验");
    setSupportActionBar(toolbar);
    SetButton1();
    SetButton2();
    SetButton3();
    SetButton4();
  }



  @Override public boolean onCreateOptionsMenu(Menu menu) {
    menu.add(0, 1, 0, "返回上一个Activity");
    menu.add(0, 2, 1, "跳转到下一个Activity");
    return true;
  }

  @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) {
    switch (item.getItemId()) {
      case 1:
        BackToLastActivity();
        break;
      case 2:
        GoToNextActivity();
        break;
    }
    return true;
  }

  private void GoToNextActivity() {
    Intent intent = new Intent(this, DataStoreActivity.class);
    startActivity(intent);
  }
  private void BackToLastActivity() {
    Intent intent = new Intent(this, StyleActivity.class);
    startActivity(intent);

  }

  private void SetButton1() {
    Button button = (Button) findViewById(R.id.frame_anim_button);
    button.setOnClickListener(new View.OnClickListener() {
      @Override public void onClick(View v) {
        JumpToFrameActivity();
      }
    });

  }
  private void SetButton2() {
    Button button = (Button) findViewById(R.id.tween_anim_button);
    button.setOnClickListener(new View.OnClickListener() {
      @Override public void onClick(View v) {
        JumpToTweenFrameActivity();
      }
    });
  }
  private void SetButton3() {
    Button button = (Button) findViewById(R.id.video_button);
    button.setOnClickListener(new View.OnClickListener() {
      @Override public void onClick(View v) {
        JumpToVideoActivity();
      }
    });
  }
  private void SetButton4() {
    Button button = (Button) findViewById(R.id.picture_button);
    button.setOnClickListener(new View.OnClickListener() {
      @Override public void onClick(View v) {
        JumpToPictureActivity();
      }
    });
  }
  private void JumpToFrameActivity() {
    Intent intent = new Intent(this, AnimActivity.class);
    intent.putExtra("title","frame");
    startActivity(intent);
  }
  private void JumpToTweenFrameActivity() {
    Intent intent = new Intent(this, AnimActivity.class);
    intent.putExtra("title","tween");
    startActivity(intent);
  }
  private void JumpToVideoActivity() {
    Intent intent = new Intent(this, VideoActivity.class);
    startActivity(intent);

  }
  private void JumpToPictureActivity() {
    Intent intent = new Intent(this, LocalPicActivity.class);
    startActivity(intent);

  }
}
